package de.latzko.pattern.monteCarlo

trait Mesure {
  var chi = 0.0;
  var mSum = 0.0;
  var mSqSum = 0.0;
  var nChi = 0;

  def mesure(spins: Array[Int], n: Int, q: Int): Unit = {
    var arr = new Array[Int](q)
    spins.foreach(x => arr(x) += 1)
    val Nmax = arr.reduceRight(_ max _)
    val m = ((Nmax.asInstanceOf[Double] / n) * q - 1) / (q - 1)
    mSum += m
    mSqSum += m * m
    nChi += 1

  }

  def computeAverages(): (Double, Double) = {
    val mean = mSum / nChi
    val moment = mSqSum / nChi
    return (mean, moment)
  }

  def init(){
    chi = 0.0;
    mSum = 0.0;
    mSqSum = 0.0;
    nChi = 0;
  }
  
}